<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<title></title>
		<meta name="description" content="overview & stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link href="static/css/bootstrap.min.css" rel="stylesheet" />
		<link href="static/css/bootstrap-responsive.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="static/css/font-awesome.min.css" />
		<!-- 下拉框 -->
		<link rel="stylesheet" href="static/css/chosen.css" />
		<link rel="stylesheet" href="static/css/ace.min.css" />
		<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
		<link rel="stylesheet" href="static/css/ace-skins.min.css" />
		<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
		<!--提示框-->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script>
		
<script type="text/javascript">
	$(top.hangge());
	$(document).ready(function(){
/* 		if($("#user_id").val()!=""){
			$("#loginname").attr("readonly","readonly");
			$("#loginname").css("color","gray");
		} */
	});
	
	//保存
	function save(){
		if($("#ROLEID").val()==""){
			
			$("#ROLEID").tips({
				side:3,
	            msg:'选择角色',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#ROLEID").focus();
			return false;
		}
		if($("#NAME").val()=="" || $("#NAME").val()=="此用户名已存在!"){
			
			$("#NAME").tips({
				side:3,
	            msg:'输入用户名',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#NAME").focus();
			$("#NAME").val('');
			$("#NAME").css("background-color","white");
			return false;
		}else{
			$("#NAME").val(jQuery.trim($('#NAME').val()));
		}
		
		if($("#user_id").val()=="" && $("#PASSWORD").val()==""){
			
			$("#PASSWORD").tips({
				side:3,
	            msg:'输入密码',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#PASSWORD").focus();
			return false;
		}
		if($("#PASSWORD").val()!=$("#chkpwd").val()){
			
			$("#chkpwd").tips({
				side:3,
	            msg:'两次密码不相同',
	            bg:'#AE81FF',
	            time:3
	        });
			
			$("#chkpwd").focus();
			return false;
		}
		if($("#NAME").val()==""){
			
			$("#NAME").tips({
				side:3,
	            msg:'输入姓名',
	            bg:'#AE81FF',
	            time:3
	        });
			$("#NAME").focus();
			return false;
		}   
		var dialCheckResult = $("input[name='IS_ACTIVATE']:checked").val(); 
		if(dialCheckResult=="" || dialCheckResult==undefined){ 
			$("#radio").tips({
				side:3,
	            msg:'请选择是否启用',
	            bg:'#AE81FF',
	            time:3
	        });
			$("#radio").focus();
			return false;
		}
		//服务器校验 
				var data = JSON.stringify(formToObject($("#userForm"))); 
				var url = '<%=basePath%>emp/add.do'; 
				if($("#msg").val()=="" || $("#msg").val()!="add"){ 
					url = '<%=basePath%>emp/edit.do';
				} 
				//alert(url+"--"+$("#msg").val());
				$.ajax({
					type: "POST",
					url: url,
			    	data: {data:data},
					dataType:'json',
					cache: false,
					success: function(data){ 
						//alert("ok"); 
						//console.log(data);
						if("success" == data.result){
/* 							$("#zhongxin").hide();
							$("#zhongxin2").show(); */ 
							document.getElementById('zhongxin').style.display = 'none'; 
							top.Dialog.close();
							top.Dialog.closeCurrent(); 
						}else if("failed" == data.result){
							$("#NAME").tips({
								side : 1,
								msg : "用户名已存在",
								bg : '#FF5080',
								time : 15
							});
							$("#NAME").focus();
						}
					}
				});
		
			//$("#userForm").submit();
	}
	
	
</script>
	</head>
<body>
	<form action="emp/${msg }.do" name="userForm" id="userForm" method="post">
		<input type="hidden" name="ID"  value="${pd.ID }"/> 
		<input type="hidden" id="msg" value="${msg}"/>
		<div id="zhongxin">
		<table>
			
			<c:if test="${fx != 'head'}">
			<c:if test="${pd.ROLE_ID != '1'}">	
			<tr>
				<td> 
				<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<small style="color: red;">*</small>角色:</span>
				<select class="chzn-select" name="ROLEID" id="ROLEID" data-placeholder="请选择角色" style="vertical-align:top;">
				<option value=""></option>
				<option value="1">管理员</option>
				</select>
				</td>
			</tr> 
			<tr><td>&nbsp;<td></tr>
			</c:if>
			</c:if>
			
			
			<tr>  
				<td>
					<span><small style="color: red;">*</small>用户姓名:</span>
					<input type="text" name="NAME" id="NAME" value="${pd.NAME }" maxlength="32" placeholder="这里输入用户名" title="用户名"
				</td>
			</tr> 
			<tr><td>&nbsp;<td></tr>
			<tr> 
				<td> 
					<span><small style="color: red;">*</small>登录密码:</span> 
					<input type="password" name="PASSWORD" id="PASSWORD"  maxlength="32" placeholder="输入密码" title="密码"/> 
				</td>
			</tr> 
			<tr><td>&nbsp;<td></tr>
			<tr>  
				<td>
					<span><small style="color: red;">*</small>确认密码:</span>
					<input type="password" name="chkpwd" id="chkpwd"  maxlength="32" placeholder="确认密码" title="确认密码" /> 
				</td>
			</tr>  
			<tr><td>&nbsp;<td></tr>
			<tr>
				<td>  
						<span><small style="color: red;">*</small>账号状态:</span>
						<input type="radio"  id="radio" name="IS_ACTIVATE" value="0"  <c:if test="${pd.IS_ACTIVATE == 0 }">checked</c:if>><span class="lbl"> 启用</span>
		  				<input type="radio"  id="radio1"  name="IS_ACTIVATE" value="1"<c:if test="${pd.IS_ACTIVATE == 1 }">checked</c:if>><span class="lbl" > 禁用</span>
				</td>  
			</tr> 
			<tr> 
				<td><span><small style="color: gray;">禁用状态下账号无法登陆后台</small></span></td>
			</tr>
			<tr>
				<td style="text-align: center;">
					<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
					<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
				</td>
			</tr>
		</table>
		</div>
		
		<div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
		
	</form>
	
		<!-- 引入 -->
		<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
		<script src="static/js/bootstrap.min.js"></script>
		<script src="static/js/ace-elements.min.js"></script>
		<script src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script src="static/js/myjs/public/public.js"></script>
		<script type="text/javascript">
		
		$(function() {
			
			//单选框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			
			//日期框
			$('.date-picker').datepicker();
			
		});
		
		</script>
	
</body>
</html>